<template>
  <view class="group-info-container">
    <!-- Left: Category List (e.g., 100M, 200M) -->
    <view class="category-list">
      <view
        v-for="(category, index) in categories"
        :key="index"
        :class="['category-item', { active: activeCategoryIndex === index }]"
        @click="selectCategory(index)"
      >
        {{ category.name }}
      </view>
    </view>

    <!-- Right: Details List -->
    <view class="details-list">
      <view
        v-if="activeCategory"
        v-for="(item, itemIndex) in activeCategory.groups"
        :key="itemIndex"
        class="detail-item"
      >
        <view class="color-bar" :style="{ backgroundColor: item.name.includes('男子') ? '#1D428A' : item.name.includes('女子') ? '#C8102E' : item.name.includes('混合') ? '#D87E04' : '#1D428A' }"></view>
        <view class="detail-info">
          <text class="detail-name">{{ item.name }}</text>
          <text class="detail-restriction">{{ item.samll_age ? item.samll_age : '不限年龄'}}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, computed } from 'vue';

const props = defineProps({
  categories: {
    type: Array,
    default: () => []
  }
});

const activeCategoryIndex = ref(0);

const activeCategory = computed(() => {
  return props.categories[activeCategoryIndex.value];
});

const selectCategory = (index) => {
  activeCategoryIndex.value = index;
};
</script>

<style lang="scss" scoped>
.group-info-container {
  display: flex;
  background-color: #ffffff;
  border-radius: 16rpx;
  overflow: hidden;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  min-height: 500rpx; /* Ensure a minimum height */
}

.category-list {
  width: 180rpx;
  background-color: #f7f8fa;
  flex-shrink: 0;
  padding: 20rpx 0;
  .category-item {
    padding: 24rpx;
    font-size: 28rpx;
    color: #666;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    &.active {
      background-color: #2979ff;
      color: white;
      font-weight: bold;
    }
  }
}

.details-list {
  flex-grow: 1;
  padding: 20rpx;
  .detail-item {
    display: flex;
    align-items: center;
    padding: 20rpx 0;
    border-bottom: 1rpx solid #f0f0f0;
    &:last-child {
      border-bottom: none;
    }
  }
  .color-bar {
    width: 6rpx;
    height: 30rpx;
    margin-right: 20rpx;
    border-radius: 3rpx;
  }
  .detail-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding-right: 15rpx;

    .detail-name {
      font-size: 28rpx;
      color: #333;
    }
    .detail-restriction {
      font-size: 26rpx;
      color: #999;
    }
  }
}
</style>